package com.yudaob2b.backend.modules.job.task;

import com.yudaob2b.business.constant.RedisConstant;
import com.yudaob2b.common.utils.HttpUtils;
import com.yudaob2b.common.utils.IPUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 酒店静态信息落地任务
 *
 * @author Kidd.Tan
 * @email 298023780@qq.com
 * @date 7/16/18 10:17 PM
 */
@Component("localHotelListTask")
public class LocalHotelListTask {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${elong.host.url}")
    private String ELONG_HOST_URL;

    @Autowired
    private RedisTemplate redisTemplate;

    public void run() {
        logger.info("-------酒店静态信息落地定时任务启动--------");
        if (redisTemplate.opsForValue().get(RedisConstant.REDIS_LOCK_KEY_LOCAL_HOTEL_LIST) == null) {
            StringBuilder urlBuilder = new StringBuilder();
            urlBuilder.append(ELONG_HOST_URL).append("/api/local/hotelList/refresh");
            HttpUtils.get(urlBuilder.toString(), true);
        } else {
            logger.info("-------酒店静态信息落地任务正在运行--------");
        }
    }
}
